from dotenv import load_dotenv
import sys
import os
from pathlib import Path


"""
# 获取当前文件的目录
current_dir = os.path.dirname(__file__)

# 构建到 conf/.qwen 的相对路径
conf_file_path_qwen = os.path.join(current_dir, '..', 'conf', '.qwen')

# 加载千问环境变量
load_dotenv(dotenv_path=conf_file_path_qwen)
"""

def get_qwen_models():
    """
    加载千问系列大模型
    """
    # 获取当前文件所在的目录的父级目录，并添加到 sys.path
    current_dir = os.getcwd()
    # parent_dir = os.path.dirname(current_dir)
    sys.path.append(current_dir)

    # 现在可以从上一级目录中导入模块
    from package.SysConfigManager import SysConfigManager
    sysConfig = SysConfigManager(config_path = "./config/sysconfig.json")
    
    conf_file_path_qwen = sysConfig.get_config_path("DASHSCOPE_API_KEY_FILE_PATH")
    
    # 加载千问环境变量
    load_dotenv(dotenv_path=conf_file_path_qwen)
    
    # llm 大模型
    from langchain_community.llms.tongyi import Tongyi
    llm = Tongyi(model="qwen-turbo", temperature=0.1, top_p=0.7, max_tokens=1024)

    # chat 大模型
    from langchain_community.chat_models import ChatTongyi
    chat = ChatTongyi(model="qwen-turbo", temperature=0.01, top_p=0.2, max_tokens=1024)

    # embedding 大模型
    from langchain_community.embeddings import DashScopeEmbeddings
    embed = DashScopeEmbeddings(model="text-embedding-v3")

    # rerank 模型
    from langchain_community.document_compressors.dashscope_rerank import DashScopeRerank
    rerank = DashScopeRerank(model="gte-rerank",top_n=3)

    return llm, embed , rerank